home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / asm_msc1.arc / AUTODATE.ASM < prev    next >
Assembly Source File  |  1988-11-20  |  14KB  |  436 lines

  1.          page    63,132
  2.          title   AUTODATE --- Display and reset Date and Time
  3. ;=====================================================================
  4. ; Name:     AUTODATE, automatic date routine.
  5. ; Function: Set the date and time from user or file input.
  6. ; Input:    1) after re-boot, the date and time are read
  7. ;              from "AUTODATE.DAT",
  8. ;           2) otherwise, DOS functions return current date and time.
  9. ; Output:   1) the date and time are set via DOS function calls,
  10. ;           2) the date and time are saved in file "AUTODATE.DAT".
  11. ; Notes:
  12. ;           Written for the IBM PC by Vernon Buerg, October 1983,
  13. ;           and is supplied for public domain use.
  14. ;=====================================================================
  15. ;
  16. ;
  17. cseg     segment PARA public 'CODE'
  18.          assume  cs:cseg,ds:cseg,es:cseg
  19.          org     100h
  20. autodate PROC    FAR
  21.          push    ds                      ;save for linkage
  22.          xor     ax,ax                   ;clear for return
  23.          push    ax                      ;put in stack
  24. ;
  25.          mov     dx,offset filename      ;file to open
  26.          call    open                    ;open for input/output
  27. ;
  28.          call    getdate
  29. ;
  30. ; If the current date is 01-01-1980, power was turned off
  31. ;
  32.          mov     si,offset ipldate       ;date if new boot
  33.          mov     di,offset month         ;the current date
  34.          cmps    ds:byte ptr[si],es:[di]
  35.          jne     print1                  ;no, display date/time
  36. ;
  37.          mov     cx,12                   ;length for date record
  38.          lea     bx,month                ;buffer address
  39.          call    read                    ;get a record
  40. ;
  41.          mov     cx,10                   ;length for time record
  42.          lea     bx,hour                 ;buffer address
  43.          call    read                    ;get a record
  44. ;
  45.          jmp     print2                  ;now prompt
  46. ;
  47. print1:
  48.          call    gettime                 ;current time if not read
  49. print2:
  50.          mov     dx,offset pr_date       ;prompt for DATE
  51.          lea     bx,month                ;where to reply
  52.          call    console                 ;read the DATE
  53. ;
  54.          call    setdate                 ;set the date
  55. ;
  56.          mov     dx,offset pr_time       ;prompt for TIME
  57.          lea     bx,hour                 ;overlay with reply
  58.          call    console                 ;read the TIME
  59. ;
  60.          call    settime                 ;set the time
  61.          page
  62. ;============================;
  63. ; Re-write Date/Time Records ;
  64. ;============================;
  65.          mov     byte ptr end_date,13    ;for end of record
  66.          mov     byte ptr end_date[1],10
  67.          mov     byte ptr end_time,13    ;for end of record
  68.          mov     byte ptr end_time[1],10
  69. ;
  70.          mov     cx,0                    ;new file offset of zero
  71.          mov     dx,cx
  72.          mov     al,0                    ;to use CX:DX offset
  73.          mov     bx,handle               ;supply file handle
  74.          mov     ah,42h                  ;to move file pointer
  75.          int     21h
  76.          mov     cx,12                   ;length of date record
  77.          lea     bx,month                ;addr of data
  78.          call    write                   ;re-write date record
  79. ;
  80.          mov     cx,10                   ;length of time record
  81.          lea     bx,hour                 ;addr of time
  82.          call    write                   ;re-write time data
  83. ;
  84.          mov     bx,handle               ;file handle
  85.          call    close                   ;all done
  86.          RET
  87.          page
  88.          subttl  Get current date
  89. ;===================;
  90. ; GET CURRENT DATE  ;
  91. ;===================;
  92. getdate  proc    near
  93.          push    ax
  94.          push    cx
  95.          push    dx
  96.          mov     ah,2Ah ;DOS DATE function
  97.          int     21h    ;issue request
  98. ;
  99.          mov     ax,cx ;get year(19xx)
  100.          sub     ax,1900
  101.          aam
  102.          xchg    al,ah
  103.          or      year,ax
  104.          mov     al,dh ;get month
  105.          aam
  106.          xchg    al,ah
  107.          or      month,ax
  108.          mov     al,dl ;get day
  109.          aam
  110.          xchg    al,ah
  111.          or      day,ax
  112.          pop     dx
  113.          pop     cx
  114.          pop     ax
  115.          ret
  116. getdate  endp
  117.          page
  118.          subttl  Display current time
  119. ;==================;
  120. ; GET CURRENT TIME ;
  121. ;==================;
  122. gettime  proc    near
  123.          push    ax
  124.          push    cx
  125.          push    dx
  126.          mov     ah,2ch ;DOS time function
  127.          int     21h    ;issue request
  128. ;
  129.          mov     al,ch ;get hours
  130.          aam
  131.          xchg    al,ah
  132.          or      hour,ax
  133.          mov     al,cl ;get minutes
  134.          aam
  135.          xchg    al,ah
  136.          or      minute,ax
  137.          mov     al,dh ;get seconds
  138.          aam
  139.          xchg    al,ah
  140.          or      second,ax
  141. ;
  142.          pop     dx
  143.          pop     CX
  144.          pop     ax
  145.          ret
  146. gettime  endp
  147.          page
  148.          subttl  SETTIME - set time from user input
  149. ;===========================;
  150. ;        SETTIME            ;
  151. ;===========================;
  152. settime  proc    near
  153.          push    ax
  154.          push    bx
  155.          push    cx
  156.          push    dx
  157. ;
  158. settimer:
  159.          sub     cx,cx                   ;clear AF flag
  160.          mov     ax,word ptr hour        ;get ASCII hours
  161.          aaa                             ;adjust AL to ASCII
  162.          xchg    al,ah                   ;switch to other byte
  163.          aaa                             ;adjust other byte
  164.          aad                             ;convert to binary
  165.          add     ch,al                   ;copy hours
  166.          mov     ax,word ptr minute      ;get ASCII minutes
  167.          aaa                             ;adjust AL to ASCII
  168.          xchg    al,ah                   ;switch to other byte
  169.          aaa                             ;adjust other byte
  170.          aad                             ;convert to binary
  171.          add     cl,al                   ;copy minutes
  172.          mov     ax,word ptr second      ;get ASCII seconds
  173.          aaa                             ;adjust AL to ASCII
  174.          xchg    al,ah                   ;switch to other byte
  175.          aaa                             ;adjust other byte
  176.          aad                             ;convert to binary
  177.          sub     dx,dx                   ;no hundreths
  178.          mov     dh,al
  179. ;
  180.          mov     ah,2dh                  ;set time
  181.          int     21h
  182. ;
  183.          cmp     al,0                    ;set okay?
  184.          je      timeset                 ;yes, all done
  185. ;
  186. timebad:
  187.          mov     ah,9                    ;no, print message
  188.          mov     dx,offset timemsg
  189.          int     21h
  190.          mov     dx,offset pr_time       ;prompt for TIME
  191.          lea     bx,hour                 ;overlay with reply
  192.          call    console                 ;read the TIME
  193.          jmp     settimer                ;try again
  194. ;
  195. timeset:
  196.          pop     dx
  197.          pop     cx
  198.          pop     bx
  199.          pop     ax
  200.          ret
  201. settime  endp
  202.          page
  203.          subttl  SETDATE - set DATE from user input
  204. ;==========================;
  205. ;        SETDATE           ;
  206. ;==========================;
  207. setdate  proc    near
  208.          push    ax
  209.          push    bx
  210.          push    cx
  211.          push    dx
  212. ;
  213. setdates:
  214.          cmp     byte ptr month[2],'-'  ;proper delimiter?
  215.          jne     datebad                ;no, prompt again
  216.          cmp     byte ptr day[2],'-'
  217.          jne     datebad
  218. ;
  219.          sub     dx,dx                  ;clears AF for AAA
  220.          mov     ax,word ptr month      ;get ASCII month
  221.          aaa                            ;adjust AL to ASCII
  222.          xchg    al,ah                  ;switch to other byte
  223.          aaa                            ;adjust other byte
  224.          aad                            ;convert to binary
  225.          add     dh,al                  ;put month in dh,clear AF
  226.          mov     ax,word ptr day        ;get ASCII day
  227.          aaa
  228.          xchg    al,ah
  229.          aaa
  230.          aad
  231.          add     dl,al                  ;put day in DL,clear AF
  232.          mov     ax,word ptr year       ;get ASCII year
  233.          aaa
  234.          xchg    al,ah
  235.          aaa
  236.          aad
  237.          mov     cl,al                  ;put year in CL
  238.          add     cx,1900                ;still this century
  239. ;
  240.          mov     ah,2bh                 ;set date function
  241.          int     21h
  242. ;
  243.          cmp     al,0                   ;set okay?
  244.          je      dateset                ;yes, all done
  245. datebad:
  246.          mov     ah,9                   ;no, print message
  247.          mov     dx,offset datemsg
  248.          int     21h
  249. ;
  250.          mov     dx,offset pr_date       ;prompt for DATE
  251.          lea     bx,month                ;where to reply
  252.          call    console                 ;read the DATE
  253. ;
  254.          jmp     setdates                ;and try it again
  255. ;
  256. dateset:
  257.          pop     dx
  258.          pop     cx
  259.          pop     bx
  260.          pop     ax
  261.          ret
  262. setdate  endp
  263.          page
  264.          subttl  CONSOLE - Read console input
  265. ;=====================================;
  266. ;        CONSOLE                      ;
  267. ; INPUT:  DX, offset to prompt        ;
  268. ;         BX, LEA of reply            ;
  269. ; OUTPUT: field at BX has text        ;
  270. ; NOTES:  no editing performed        ;
  271. ;=====================================;
  272. console  proc    near
  273.          push    ax
  274.          push    cx
  275. ;
  276.          mov     ah,9            ;print function
  277.          int     21h             ;prompt for response
  278. cons1:
  279.          mov     ah,1            ;read console character
  280.          int     21h
  281. ;
  282.          cmp     al,0       ;extended code?
  283.          jne     cons2      ;no, have one character
  284.          mov     ah,1ch     ;yes, get next code
  285.          int     21h
  286.          jmp     cons1      ;ignore it
  287. cons2:
  288.          cmp     al,13      ;is it ENTER?
  289.          je      consend    ;yes, all over
  290.          mov     [bx],al    ;copy inputted character
  291.          inc     bx         ;increment target offset
  292.          jmp     cons1      ;and get next character
  293. ;
  294. consend:
  295.          pop     cx
  296.          pop     ax
  297.          ret
  298. console  endp
  299.          page
  300.          subttl  OPEN - Open file given filename
  301. ;===================================;
  302. ;        OPEN                       ;
  303. ; input:  DX has offset to filename ;
  304. ; output: BX has handle             ;
  305. ;         field HANDLE has handle   ;
  306. ;===================================;
  307. open     proc    near
  308.          push    ax
  309.          push    cx
  310. ;
  311.          mov     ax,2            ;for read/write
  312.          mov     ah,3dh          ;open a file
  313.          int     21h
  314.          mov     handle,ax       ;save file handle
  315. ;
  316.          jnc     openend
  317.          aam
  318.          xchg    al,ah
  319.          or      opencode,ax
  320.          mov     dx,offset openmsg
  321.          mov     ah,9
  322.          int     21h
  323. ;
  324. openend:
  325.          pop     cx
  326.          pop     ax
  327.          ret
  328. open     endp
  329.          page
  330.          subttl  CLOSE - Close file given handle from open
  331. ;=======================;
  332. ;        CLOSE          ;
  333. ; input:  BX has handle ;
  334. ;=======================;
  335. close    proc    near
  336.          push    ax
  337.          mov     ah,3eh          ;close a file handle
  338.          int     21h
  339.          pop     ax
  340.          ret
  341. close    endp
  342.          page
  343.          subttl  READ - Read disk record
  344. ;================================;
  345. ;        READ                    ;
  346. ; input:  CX has length          ;
  347. ;         BX has addr rec        ;
  348. ;         HANDLE has file handle ;
  349. ;================================;
  350. read     proc    near
  351.          push    ax
  352.          push    dx
  353.          mov     recaddr,bx      ;save record address
  354.          mov     numbytes,cx     ;length to clear
  355. readclr: mov     bx,0            ;clear to zero
  356.          inc     bx              ;increment to next byte
  357.          loop    readclr         ;for entire record
  358. ;
  359.          mov     bx,handle       ;get file handle from open
  360.          mov     dx,recaddr      ;offset to record buffer
  361.          mov     cx,numbytes     ;number of bytes to read
  362. ;
  363.          mov     ah,3fh          ;read from a file
  364.          int     21h
  365. ;
  366. readend:
  367.          pop     dx
  368.          pop     ax
  369.          ret
  370. read     endp
  371.          page
  372.          subttl  WRITE - Read disk record
  373. ;================================;
  374. ;        WRITE                   ;
  375. ; input:  CX has length          ;
  376. ;         BX has addr rec        ;
  377. ;         HANDLE has file handle ;
  378. ;================================;
  379. write    proc    near
  380.          push    ax
  381.          push    dx
  382.          mov     dx,bx           ;set record address
  383.          mov     bx,handle       ;set file handle
  384. ;
  385.          mov     ah,40h          ;write to file
  386.          int     21h
  387. ;
  388. writend:
  389.          pop     dx
  390.          pop     ax
  391.          ret
  392. write    endp
  393.          page
  394.          subttl  Constants and work areas
  395. pr_date  db      27,'[2J'
  396.          db      'Current date is: '
  397. month    dw      '00'
  398.          db      '-'
  399. day      dw      '00'
  400.          db      '-19'
  401. year     dw      '00'
  402. end_date dw      2020h
  403.          db      27,'[2;1H','Enter new date: '
  404.          db      '$'
  405. pr_time  db      27,'[3;1H'
  406.          db      'Current time is: '
  407. hour     dw      '00'
  408.          db      ':'
  409. minute   dw      '00'
  410.          db      ':'
  411. second   dw      '00'
  412. end_time dw      0
  413.          db      27,'[4;1H','Enter new time: '
  414.          db      '$'
  415. ;
  416. ipldate  db      '01-01-1980'
  417. datemsg  db      27,'[3;1H','Date invalid',7,'$'
  418. timemsg  db      27,'[5;1H','Time invalid',7,'$'
  419. ten      db      10
  420. ;
  421. filename db      'a:autodate.dat',0  ;drive:filename.ext
  422. handle   dw      0                   ;file handle from open
  423. ;
  424. openmsg  db      'Open code: '
  425. opencode dw      '00'
  426.          db      '  $'
  427. numbytes dw      0                   ;bytes to read
  428. bytes    dw      0                   ;bytes read
  429. recaddr  dw      0                   ;addr of i/o area
  430. rec      db      80 dup(0)           ;file record area
  431. ;
  432. autodate ENDP
  433. cseg     ends
  434.          end     autodate
  435.  i/o area
  436. rec      db      80 dup(0)           ;file record area